home *** CD-ROM | disk | FTP | other *** search
- Path: titan.fullerton.edu!grosin
- From: grosin@titan.fullerton.edu (Gil Rosin)
- Newsgroups: comp.lang.c++
- Subject: HELP - templates won't compile via Project files...
- Date: 2 Mar 1996 07:24:59 GMT
- Organization: California State University at Fullerton
- Message-ID: <4h8t4b$oi3@wintermute.ecs.fullerton.edu>
- NNTP-Posting-Host: titan.ecs.fullerton.edu
- X-Newsreader: TIN [version 1.2 PL2]
-
- The title says it all, I'm a newbie to C++ and wrote a stack package that
- just did integers, well, I recently tried to convert it to a template.
-
- Anyways, when I try to compile it, I get linker errors saying that the
- functions can not be found, yet they EXIST!
-
- I only get those errors for functions that are defined out of line, for example
- I have 3 files:
-
- STACK.H - class declaration
- STACK.CPP - a few STACK functions
- TEST.CPP - the driver
-
- I have most of the functions defined inline because they are small, but 3
- I have out of line, Push, Pop and Flush.
-
- Anyways, in stack.h, I define them in the class like:
-
- template <class ElementType>
- class Stack
- {
- public:
- void Push(const ElementType & Element);
- ElementType Pop(void);
- void Flush(void);
- }
-
- then in stack.cpp I include Stack.h, and have the functions defined as:
-
- template <class ElementType>
- void Stack<ElementType>::Flush(void)
- {
- }
-
- template <class ElementType>
- void Stack<ElementType>::Push(const ElementType & Element)
- {
- }
-
- template <class ElementType>
- ElementType Stack<ElementType>::Pop(void)
- {
- }
-
- when I compile it in a project file in Borland C++ v3.1, It compiles ok, but
- I get 3 linker errors:
-
- undefined symbol Flush........
- undefined symbol Push.... in TEST.CPP
- ....
-
- etc. BUT here's the kicker, when I lump all the 3 files into one file and THEN
- compile the one file, everything works fine, what is going on here?
-
- Please reply via email to grosin@titan.fullerton.edu
-
- Thanks.
-
- .
-
-